// LevelDataProvider.java
package com.SouthernWall_404.age_tool.common.API.Capability.Provider;

import com.SouthernWall_404.age_tool.common.API.Capability.TriggersCap;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class TriggersCapProvider implements ICapabilitySerializable<CompoundTag> {
    private TriggersCap triggersCap;

    public static final Capability<TriggersCap> TRIGGERSCAP = CapabilityManager.get(new CapabilityToken<>(){});

    private final LazyOptional<TriggersCap> lazyOptional=LazyOptional.of(()->this.triggersCap);

    public TriggersCapProvider() {
        this.triggersCap = new TriggersCap();
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
        return getCapability(cap);
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap) {
        if(cap== TRIGGERSCAP)
        {
            return lazyOptional.cast();
        }
        else
        {
            return LazyOptional.empty();
        }
    }

    @Override
    public CompoundTag serializeNBT() {
        return triggersCap.serializeNBT();
    }

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        triggersCap.deserializeNBT(nbt);
    }
}